import { stringify } from 'qs';
import request from '@/utils/request';

const prefix = 'http://127.0.0.1:7001/';

// 横幅（轮播图 宣传图）Banners GET
export async function getBanners(position, currentPage) {
  const url = `${prefix}banners?position=${position}${
    currentPage ? `&currentPage=${currentPage}` : ''
  }`;
  return request(url, {
    withToken: true,
  });
}
// Banners POST
export async function postBanner(params) {
  console.log('services postBanner params', params);
  return request(`${prefix}banners`, {
    withToken: true,
    method: 'POST',
    body: params,
  });
}
// Banners PUT
export async function putBanner(id, params) {
  return request(`${prefix}banners/${id}`, {
    withToken: true,
    method: 'PUT',
    body: params,
  });
}
// Banners DELETE
export async function deleteBanner(id) {
  console.log('services postBanner id', id);
  return request(`${prefix}banners/${id}`, {
    withToken: true,
    method: 'DELETE',
  });
}
// 获取上传令牌
export async function getUploadToken() {
  return request(`${prefix}upload_token`, {
    withToken: true,
  });
}
// 用户管理
export async function getUsers(role, currentPage) {
  console.log('services getUsers role', role);
  const url = `${prefix}users?role=${role}${currentPage ? `&currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 用户管理
export async function getUserInfo() {
  const url = `${prefix}userInfo`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 用户管理 获取所有用户
export async function getAllUsers(currentPage) {
  console.log('services getUsers currentPage', currentPage);
  const url = `${prefix}users${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// Users POST
export async function postUsers(params) {
  console.log('services postUsers params', params);
  return request(`${prefix}users`, {
    method: 'POST',
    withToken: true,
    body: params,
  });
}
// Users PUT
export async function putUsers(id, params) {
  console.log('putUsers params', params);
  return request(`${prefix}users/${id}`, {
    method: 'PUT',
    withToken: true,
    body: params,
  });
}
// Users DELETEResetpassword
export async function deleteUsers(id) {
  console.log('services deleteUsers id', id);
  return request(`${prefix}users/${id}`, {
    method: 'DELETE',
    withToken: true,
  });
}
// 商品 items
export async function getItems(currentPage) {
  const query = {};
  if (currentPage) query.currentPage = currentPage;
  return request(`${prefix}items${Object.keys(query).length ? `?${stringify(query)}` : ''}`, {
    withToken: true,
  });
}
// 需要审核的商品 GET
export async function getItemsByStatus(status, currentPage) {
  const query = {};
  if (currentPage) query.currentPage = currentPage;
  return request(
    `${prefix}items?status=offshelf&itemType=${status}${
      Object.keys(query).length ? `&${stringify(query)}` : ''
    }`,
    {
      withToken: true,
    }
  );
}
// 商品根据类型搜索 items
export async function getItemsByItemType(status, currentPage) {
  const query = {};
  if (currentPage) query.currentPage = currentPage;
  return request(
    `${prefix}items?itemType=${status}${Object.keys(query).length ? `&${stringify(query)}` : ''}`,
    {
      withToken: true,
    }
  );
}
// 店铺搜索
export async function getItemByTitleLike(titleLike) {
  console.log('services getItemByTitleLike titleLike', titleLike);
  return request(`${prefix}items?titleLike=${titleLike}`, {
    withToken: true,
  });
}
// 绑定支付宝
export async function postAlipayOrbank(params) {
  console.log('services postItem params', params);
  return request(`${prefix}bindAlipayOrbankCardByUser`, {
    withToken: true,
    method: 'POST',
    body: params,
  });
}
// 提现
export async function postWithdrawalByStore(params) {
  console.log('services postWithdrawalByStore params', params);
  return request(`${prefix}withdrawal`, {
    withToken: true,
    method: 'POST',
    body: params,
  });
}
// 商品  POST items
export async function postItem(params) {
  console.log('services postItem params', params);
  return request(`${prefix}items`, {
    withToken: true,
    method: 'POST',
    body: params,
  });
}
// put 商品 items
export async function putItem(id, params) {
  console.log('services putItem id', id);
  console.log('services putItem params', params);
  return request(`${prefix}items/${id}`, {
    withToken: true,
    method: 'PUT',
    body: params,
  });
}
// delete 商品 items
export async function deleteItem(id) {
  return request(`${prefix}items/${id}`, {
    withToken: true,
    method: 'DELETE',
  });
}
// 俱乐部 Clubs GET
export async function getStores(currentPage) {
  const query = {};
  if (currentPage) query.currentPage = currentPage;
  return request(`${prefix}stores${Object.keys(query).length ? `?${stringify(query)}` : ''}`, {
    withToken: true,
  });
}
// 需要审核的店铺 GET
export async function getStoresByStatus(currentPage) {
  const query = {};
  if (currentPage) query.currentPage = currentPage;
  return request(
    `${prefix}stores?status=draft${Object.keys(query).length ? `&${stringify(query)}` : ''}`,
    {
      withToken: true,
    }
  );
}
// 店铺搜索
export async function getStoresByNameLike(nameLike) {
  console.log('services getStoresByNameLike nameLike', nameLike);
  return request(`${prefix}stores?nameLike=${nameLike}`, {
    withToken: true,
  });
}

// Clubs POST
export async function postStores(params) {
  console.log('services postStores params', params);
  return request(`${prefix}stores`, {
    withToken: true,
    method: 'POST',
    body: params,
  });
}
// Clubs POST
// 上传店铺信息
export function postStoresById(id, params) {
  console.log('services postStores params', params);
  const url = `${prefix}stores/${id}`;
  console.log('services getStores url', url);
  return request(url, {
    method: 'PUT',
    withToken: true,
    body: params,
  });
}

// Clubs PUT
export async function putStores(id, params) {
  console.log('services putStores params', params);
  return request(`${prefix}stores/${id}`, {
    withToken: true,
    method: 'PUT',
    body: params,
  });
}
// Clubs DELETE
export async function deleteStores(id) {
  console.log('services deleteStores id', id);
  return request(`${prefix}stores/${id}`, {
    withToken: true,
    method: 'DELETE',
  });
}
//  configs user/homePage
export async function getConfigs() {
  return request(`${prefix}configs`, {
    withToken: true,
  });
}
//  postConfigs
export async function putConfig(key, value) {
  console.log('putConfig key', key);
  console.log('putConfig value', value);
  return request(`${prefix}configs/${key}`, {
    withToken: true,
    method: 'PUT',
    body: { value },
  });
}
//  configs user/homePage
export async function getConfigsByPhone() {
  return request(`${prefix}configs/customerServicePhone`, {
    withToken: true,
  });
}
//  postConfigs
export async function putConfigByPhone(value) {
  console.log('putConfig value', { value });
  return request(`${prefix}configs/customerServicePhone`, {
    withToken: true,
    method: 'PUT',
    body: { value },
  });
}
// 会员等级
export async function getVipRank(currentPage) {
  const url = `${prefix}vipRanks${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 会员等级 POST
export async function postVipRank(params) {
  console.log('services getStoreClass postStoreClass', params);
  return request(`${prefix}vipRanks`, {
    method: 'POST',
    withToken: true,
    body: params,
  });
}
// 会员等级 PUT
export async function putVipRank(id, params) {
  console.log('services getStoreClass putStoreClass params', params);
  return request(`${prefix}vipRanks/${id}`, {
    method: 'PUT',
    withToken: true,
    body: params,
  });
}
// 会员等级 DELETE
export async function deleteVipRank(id) {
  console.log('services deleteStoreClass id', id);
  return request(`${prefix}vipRanks/${id}`, {
    method: 'DELETE',
    withToken: true,
  });
}
// 获取商户店铺信息
export async function getStoresByUserId(userId) {
  console.log('services getStores userId', userId);
  const url = `${prefix}stores?userId=${userId}`;
  console.log('services getStores url', url);
  return request(url, {
    withToken: true,
  });
}
// 获取商户店铺信息
export async function getStoresById(id) {
  console.log('services getStores id', id);
  const url = `${prefix}stores/${id}`;
  console.log('services getStores url', url);
  return request(url, {
    withToken: true,
  });
}
// 获取订单信息
export async function getOrdersByStoreId(storeId, query) {
  console.log('services getOrdersByStoreId storeId', storeId);
  console.log('services getOrdersByStoreId query', query);
  const url = `${prefix}orders?storeId=${storeId}${query ? `&currentPage=${query}` : ''}`;
  console.log('services getOrdersByStoreId url', url);
  return request(url, {
    withToken: true,
  });
}
// 修改订单状态
export function putOrderByStatus(id, params) {
  console.log('services putOrderByStatus params', params);
  // console.log('services putOrder id', id);
  const url = `${prefix}orders/${id}`;
  console.log('services putOrderByStatus url', url);
  return request(url, {
    method: 'PUT',
    withToken: true,
    body: params,
  });
}
// 获取优惠券信息
export async function getClassCoupons(currentPage) {
  console.log('services getClassCoupons currentPage', currentPage);
  const url = `${prefix}classCoupons${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 获取优惠券信息
export async function getClassCouponsByType(type, currentPage) {
  console.log('services getClassCoupons currentPage', currentPage);
  const url = `${prefix}classCoupons?type=${type}${
    currentPage ? `&currentPage=${currentPage}` : ''
  }`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 获取在途佣金信息
export async function getIncomeByUser(currentPage) {
  console.log('services getIncomeByUser currentPage', currentPage);
  const url = `${prefix}waitingIncome${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}

// 获取在途佣金信息
export async function getIncomeByStores(currentPage) {
  console.log('services getIncomeByStores currentPage', currentPage);
  const url = `${prefix}storeWaitingIncome${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 上传新优惠券
export async function postClassCoupons(params) {
  console.log('services postClassCoupons');
  return request(`${prefix}classCoupons`, {
    method: 'POST',
    withToken: true,
    body: params,
  });
}
// 优惠券 DELETE
export async function deleteClassCoupons(id) {
  console.log('services postClassCoupons id', id);
  return request(`${prefix}classCoupons/${id}`, {
    method: 'DELETE',
    withToken: true,
  });
}
// 获取首页信息
export function getHomePage() {
  return request(`${prefix}user/appHomePage`, {
    withToken: true,
  });
}
// 获取验证码
export function smsCode(phone) {
  console.log('services smsCode phone', phone);
  return request(`${prefix}smsCode`, {
    method: 'POST',
    body: { phone },
  });
}
// 短信密码登录
export async function loginByPhoneAndSmsCode(params) {
  console.log('services smsCode params', params);
  return request(`${prefix}resetAndLoginBySmsCode`, {
    method: 'POST',
    body: params,
  });
}
// 分类管理
export async function getStoreClass(currentPage) {
  console.log('services getStoreClass currentPage', currentPage);
  const url = `${prefix}storeClass${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 分类管理 POST
export async function postStoreClass(params) {
  console.log('services getStoreClass postStoreClass');
  return request(`${prefix}storeClass`, {
    method: 'POST',
    withToken: true,
    body: params,
  });
}
// 分类管理 PUT
export async function putStoreClass(id, params) {
  console.log('services getStoreClass putStoreClass params', params);
  return request(`${prefix}storeClass/${id}`, {
    method: 'PUT',
    withToken: true,
    body: params,
  });
}
// 分类管理 DELETE
export async function deleteStoreClass(id) {
  console.log('services deleteStoreClass id', id);
  return request(`${prefix}storeClass/${id}`, {
    method: 'DELETE',
    withToken: true,
  });
}

// 提现审核get
export async function getWithdrawal(currentPage) {
  const url = `${prefix}withdrawal${currentPage ? `?currentPage=${currentPage}` : ''}`;
  return request(url, {
    withToken: true,
  });
}
// 提现审核 POST
export async function postWithdrawal(params) {
  console.log('services postBanner params', params);
  return request(`${prefix}withdrawal`, {
    withToken: true,
    method: 'POST',
    body: params,
  });
}
// 提现审核 PUT
export async function putWithdrawal(id, params) {
  console.log('services putWithdrawal params', params);
  return request(`${prefix}withdrawal/${id}`, {
    withToken: true,
    method: 'PUT',
    body: params,
  });
}

// 店铺审核 PUT
export async function putFacilitator(id, params) {
  console.log('services putFacilitator params', params);
  return request(`${prefix}stores/${id}`, {
    withToken: true,
    method: 'PUT',
    body: params,
  });
}

// 商品审核 PUT
export async function putItemsByAudit(id, params) {
  console.log('services putItemsByAudit params', params);
  return request(`${prefix}items/${id}`, {
    withToken: true,
    method: 'PUT',
    body: params,
  });
}

// 提现审核 DELETE
export async function deleteWithdrawal(id) {
  console.log('services postBanner id', id);
  return request(`${prefix}withdrawal/${id}`, {
    withToken: true,
    method: 'DELETE',
  });
}
//  configs user/homePage
export async function getHomePageInfo() {
  return request(`${prefix}user/homePage`, {
    withToken: true,
  });
}
// 个人日志
export async function getViewLog(currentPage) {
  console.log('services getViewLog currentPage', currentPage);
  const url = `${prefix}user/viewLog${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 团队日志
export async function getTeamViewLog(currentPage) {
  console.log('services getTeamViewLog currentPage', currentPage);
  const url = `${prefix}user/teamViewLog${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 订单管理
export async function getOrders(currentPage) {
  console.log('services getOrders currentPage', currentPage);
  const url = `${prefix}orders${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 订单管理
export async function getOrdersByStatus(currentPage) {
  console.log('services getOrders currentPage', currentPage);
  const url = `${prefix}orders?status=completed${currentPage ? `&currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 订单管理 POST
export async function postOrders(params) {
  console.log('services postOrders postStoreClass');
  return request(`${prefix}orders`, {
    method: 'POST',
    withToken: true,
    body: params,
  });
}
// 订单管理 PUT
export async function putOrders(id, params) {
  console.log('services putOrders params', params);
  return request(`${prefix}orders/${id}`, {
    method: 'PUT',
    withToken: true,
    body: params,
  });
}
// 订单管理 DELETE
export async function deleteOrders(id) {
  console.log('services deleteOrders id', id);
  return request(`${prefix}orders/${id}`, {
    method: 'DELETE',
    withToken: true,
  });
}

// 城市管理
export async function getStoreCity(currentPage) {
  console.log('services StoreCity currentPage', currentPage);
  const url = `${prefix}storeCity${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 城市管理 POST
export async function postStoreCity(params) {
  console.log('services postOrders postStoreClass');
  return request(`${prefix}storeCity`, {
    method: 'POST',
    withToken: true,
    body: params,
  });
}
// 城市管理 PUT
export async function putStoreCity(id, params) {
  console.log('services putOrders params', params);
  return request(`${prefix}storeCity/${id}`, {
    method: 'PUT',
    withToken: true,
    body: params,
  });
}
// 城市管理 DELETE
export async function deleteStoreCity(id) {
  console.log('services deleteOrders id', id);
  return request(`${prefix}storeCity/${id}`, {
    method: 'DELETE',
    withToken: true,
  });
}

// 图片管理
export async function getPictures(currentPage) {
  console.log('services StoreCity currentPage', currentPage);
  const url = `${prefix}file${currentPage ? `?currentPage=${currentPage}` : ''}`;
  console.log('url', url);
  return request(url, {
    withToken: true,
  });
}
// 图片管理 POST
export async function postPictures(params) {
  console.log('services postOrders postStoreClass');
  return request(`${prefix}file`, {
    method: 'POST',
    withToken: true,
    body: params,
  });
}
// 图片管理 PUT
export async function putPictures(id, params) {
  console.log('services putOrders params', params);
  return request(`${prefix}file/${id}`, {
    method: 'PUT',
    withToken: true,
    body: params,
  });
}
// 图片管理 DELETE
export async function deletePictures(id) {
  console.log('services deleteOrders id', id);
  return request(`${prefix}file/${id}`, {
    method: 'DELETE',
    withToken: true,
  });
}

export async function queryProjectNotice() {
  return request('/api/project/notice');
}

export async function queryActivities() {
  return request('/api/activities');
}

export async function queryRule(params) {
  return request(`/api/rule?${stringify(params)}`);
}

export async function removeRule(params) {
  return request('/api/rule', {
    method: 'POST',
    body: {
      ...params,
      method: 'delete',
    },
  });
}

export async function addRule(params) {
  return request('/api/rule', {
    method: 'POST',
    body: {
      ...params,
      method: 'post',
    },
  });
}

export async function updateRule(params) {
  return request('/api/rule', {
    method: 'POST',
    body: {
      ...params,
      method: 'update',
    },
  });
}

export async function fakeSubmitForm(params) {
  return request('/api/forms', {
    method: 'POST',
    body: params,
  });
}

export async function fakeChartData() {
  return request('/api/fake_chart_data');
}

export async function queryTags() {
  return request('/api/tags');
}

export async function queryBasicProfile() {
  return request('/api/profile/basic');
}

export async function queryAdvancedProfile() {
  return request('/api/profile/advanced');
}

export async function queryFakeList(params) {
  return request(`/api/fake_list?${stringify(params)}`);
}

export async function removeFakeList(params) {
  const { count = 5, ...restParams } = params;
  return request(`/api/fake_list?count=${count}`, {
    method: 'POST',
    body: {
      ...restParams,
      method: 'delete',
    },
  });
}

export async function addFakeList(params) {
  const { count = 5, ...restParams } = params;
  return request(`/api/fake_list?count=${count}`, {
    method: 'POST',
    body: {
      ...restParams,
      method: 'post',
    },
  });
}

export async function updateFakeList(params) {
  const { count = 5, ...restParams } = params;
  return request(`/api/fake_list?count=${count}`, {
    method: 'POST',
    body: {
      ...restParams,
      method: 'update',
    },
  });
}

export async function fakeRegister(params) {
  return request('/api/register', {
    method: 'POST',
    body: params,
  });
}

export async function queryNotices(params = {}) {
  return request(`/api/notices?${stringify(params)}`);
}
